declare @curUserId tinyInt;
set @curUserId = DATABASE_PRINCIPAL_ID();

if not exists (select * from sysobjects where 
					name = 'SMS_Message' and 
					type = 'U' and
					uid = @curUserId)
	begin
		print 'not exists'
		CREATE TABLE [SMS_Message](
			[id] [bigint] NOT NULL PRIMARY KEY IDENTITY(1,1),
			[id_in] [bigint] NOT NULL,
			[id_out] [bigint] NOT NULL,
			[id_type] [smallint] NOT NULL,
			[id_codepage] [smallint] NOT NULL
		)	
	end
else
	begin
		print 'exists!'
		select * into SMS_Message_tmp from SMS_Message
		drop table SMS_Message
		CREATE TABLE [SMS_Message](
			[id] [bigint] NOT NULL PRIMARY KEY IDENTITY(1,1),
			[id_in] [bigint] NOT NULL,
			[id_out] [bigint] NOT NULL,
			[id_type] [smallint] NOT NULL,
			[id_codepage] [smallint] NOT NULL
		)	
		SET IDENTITY_INSERT SMS_Message ON
		insert into SMS_Message ([id], [id_in], [id_out], [id_type], [id_codepage])
			select [id], [id_in], [id_out], [id_type], [id_codepage] from SMS_Message_tmp
		drop table SMS_Message_tmp
		SET IDENTITY_INSERT SMS_Message OFF
	end
